#include "rpgpch.h"

#include "WindowsInput.h"
#include "Rpg/Application.h"
#include "GLFW/glfw3.h"
namespace Rpg {
	Input* Input::m_instance = new WindowsInput();
	bool WindowsInput::isKeyPressedImpl(int keycode) const {

		auto window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow());

		int state = glfwGetKey(window, keycode);

		return state == GLFW_PRESS || state == GLFW_REPEAT;
	}
	bool WindowsInput::isMouseButtonPressedImpl(int button) const
	{

		auto window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow());

		int state = glfwGetMouseButton(window, button);

		return state == GLFW_PRESS;
	}
	std::pair<float, float> WindowsInput::GetMousePosImpl() const
	{
		auto window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow());

		double x, y;
		glfwGetCursorPos(window, &x, &y);

		return {x,y};
	}
	float WindowsInput::GetMousePosXImpl() const
	{
		auto[x,y]= GetMousePosImpl();
		return x;
	}
	float WindowsInput::GetMousePosYImpl() const
	{
		auto [x, y] = GetMousePosImpl();
		return y;
	}
}